package com.malamute.core.common;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.cafe.model.Customer;
import com.cafe.model.Product;

/**
 * @Title:SearchParam.java
 * @Package com.malamute.core.common
 * @Description 查询对象
 * @author AceGuan gjybst@163.com
 * @date 2012-1-4 下午02:05:40
 * @version v1.0
 */
public class SearchParamUtil {

	public static void simpleSeach(DetachedCriteria criteria, Map searchParam) {
		for (Iterator it = searchParam.keySet().iterator(); it.hasNext();) {
			String key = (String) it.next();
			String[] values = (String[]) searchParam.get(key);
			criteria.add(Restrictions.like(key, "%" + values[0] + "%"));
		}
	}

	public static void main(String[] args) {
		DetachedCriteria menuCriteria = DetachedCriteria
				.forClass(Product.class);
		Map searchParam = new HashMap();
		searchParam.put("aaa", new String[] { "aValue" });
		SearchParamUtil.simpleSeach(menuCriteria, searchParam);
		System.out.println(menuCriteria);

		DetachedCriteria customerCriteria = DetachedCriteria
				.forClass(Customer.class);
		Map searchParam2 = new HashMap();
		searchParam2.put("aaa", new String[] { "aValue" });
		SearchParamUtil.simpleSeach(customerCriteria, searchParam2);
		System.out.println(customerCriteria);

	}
}
